//
//  WTWelcomeViewController.swift
//  WTSinaWeibo
//
//  Created by  Wellim on 16/6/27.
//  Copyright © 2016年  Wellim. All rights reserved.
//

import UIKit
import SDWebImage
//import SnapKit
class WTWelcomeViewController: UIViewController {

    
    override func loadView() {
        view = backImagview
        
    
    
    }
    
    override func viewDidAppear(animated: Bool) {
        
        super.viewDidAppear(animated)
        
        // 更改头像的约束
        // 使用update 约束的对象的view 没有发生改变 改变top 使用
        
        self.headImageView.snp_updateConstraints { (make) in
            
            make.top.equalTo(self.view).offset(100)
        }
       
        /**
         动画
         - 01 - 动画执行时间
         - 02 - 延迟时间
         - 03 - 阻尼系数  范围 0-1  越大弹性效果越差
         - 04 - 起始速度
         
         - returns:
         */
       UIView.animateWithDuration(3.0, delay: 1.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { 
        
         self.view.layoutIfNeeded()
        
        }) { (_) in
            
            UIView.animateWithDuration(0.25, animations: { 
               
                self.messageLabel.alpha = 1.0
                
                }, completion: { (_) in
                    
            NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVCNoti, object:"welcome")
                    
            })

            
        }
        
    }


    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
       //设置视图
        setUpUI()
    }

    // MARK: - 设置视图
    private func setUpUI(){
    //添加控件
    
    view.addSubview(headImageView)
    view.addSubview(messageLabel)
        
     //设置约束
        
     headImageView.snp_makeConstraints { (make) in
        make.size.equalTo(CGSize(width: 90, height: 90))
        make.top.equalTo(view).offset(400)
        make.centerX.equalTo(view)
        
        }
        
      messageLabel.snp_makeConstraints { (make) in
        
        make.centerX.equalTo(view)
        
        make.top.equalTo(headImageView.snp_bottom).offset(16)
        
    }
        
        
    
    }
    
    
    
    

    // MARK: - 懒加载控件 
    // 背景图片
    private lazy var backImagview: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    //头像
    private lazy var headImageView:UIImageView = {
    
        let img = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        //设置layer
        img.layer.cornerRadius = 45
        img.layer.borderColor = ThemeColor.CGColor
        img.layer.borderWidth = 3
        img.layer.masksToBounds = true
        
        // 设置图片
        img.sd_setImageWithURL( NSURL(string: (WTUserAccountTools.sharedUserAccountTools.userAccount?.avatar_large)!  )
            , placeholderImage: UIImage(named: "avatar_default_big"))
          return img
    }()
    
    //文字欢迎回来
    private lazy var messageLabel:UILabel = {
     
        let label = UILabel()
        label.text = "欢迎回来"
        label.font = UIFont.systemFontOfSize(20)
        label.textColor = UIColor.grayColor()
        label.textAlignment = .Center
        //透明度
        label.alpha = 0
        
        return label
        
    }()
    
    
    


}
